﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;
using Cms.BLL;
using NHibernate;
using System.Collections;
using System.IO;

namespace Cms.Web.Tools
{
    /// <summary>
    /// Summary description for $codebehindclassname$
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class Script : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            //context.Response.Write("Hello World");

            /*
             自定义模块
             */
            string formid = EntLib.Request.GetString("formid");
            string type = EntLib.Request.GetString("type");
            string action = EntLib.Request.GetString("action");
            if (type == "getformjson")
            {
                if (action == "edit")
                {

                }
                else if (action == "list")
                {
                    string url = context.Server.MapPath(String.Format("~/CmsSystem/SysModules/{0}.js", formid));
                    if (File.Exists(url)) { 
                        //ResponseText(File.o
                        context.Response.WriteFile(url);
                    }
                    /*if (formid.ToLower() == "F3E53EEF-10C2-426D-BA87-CC1EB3AE6E9C".ToLower()) {
                        string url = context.Server.MapPath("~/");              
                    }
                    else
                    {
                        BLL.Sys_Selffom_List_Layout bll = new Cms.BLL.Sys_Selffom_List_Layout();
                        IList<Model.Sys_Selfform_List_Layout> list = bll.GetModelByFormID(formid);
                        if (list.Count > 0)
                        {
                            ResponseText(list[0].Jsondata);
                        }
                    }*/
                }
            }
            else if (type == "getrecordjson") {
                string param = EntLib.Request.GetString("param");
                if (action == "list") { 
                    //自定义表单设计
                    if (param == "F3E53EEF-10C2-426D-BA87-CC1EB3AE6E9C") {
                        BLL.Sys_Selfform bll=new Sys_Selfform();
                        ResponseText(bll.GetListJson());
                    }
                }
            }


        }
        void ResponseText(string text)
        {
            HttpContext.Current.Response.ExpiresAbsolute = DateTime.Now.AddSeconds(-1);
            HttpContext.Current.Response.Expires = -1;
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(text);
            HttpContext.Current.Response.End();
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
